<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <input type="checkbox" id="all">
    <br>
    <input type="checkbox" class="one">
    <input type="checkbox" class="one">
    <input type="checkbox" class="one">

    <script>

        var oAll = document.getElementById('all') ;
        var oOnes = document.getElementsByClassName('one') ;   // 伪数组


        // 转真数组的过程
        var arr = [] ;
        for(var i = 0 ; i < oOnes.length ; i++) {
            arr.push(oOnes[i])
        } 




        // 全选
        oAll.onclick = function() {

            for(var i = 0 ; i < oOnes.length ; i++) {
                oOnes[i].checked = oAll.checked ;
            } 
        }



        arr.forEach(function(v) {
            v.onclick = function() {
                // every 判断数组中是否每个值都满足条件
                var res = arr.every(function(v2) {
                    return v2.checked
                })
                oAll.checked = res ;
            }
        })




    </script>
    
</body>
</html>